package design;

import java.util.LinkedList;
import java.util.Queue;

// 队列实现栈，先进先出 实现 后进先出
public class leetCode225_MyStack {

    Queue<Integer> queueA = new LinkedList<>();
    Queue<Integer> queueB = new LinkedList<>();
    public leetCode225_MyStack() {

    }

    // 一直保持B空，A满
    public void push(int x) {
        queueB.add(x);
        while (!queueA.isEmpty()){
            queueB.add(queueA.poll());
        }
        while (!queueB.isEmpty()){
            queueA.add(queueB.poll());
        }
    }

    public int pop() {
        if(queueA.isEmpty()){
            return -1;
        }
        return queueA.poll();
    }

    public int top() {
        if(queueA.isEmpty()){
            return -1;
        }
        return queueA.peek();
    }

    public boolean empty() {
        return queueA.isEmpty();
    }

}
